package cn.rui.common;

import cn.dev33.satoken.exception.NotLoginException;
import cn.rui.error.DisableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 * @author 徽州大都督
 * @date 2021/6/8
 */
@RestControllerAdvice
public class GlobalException {

    /**
     * 未登录 token失效
     * @param ex
     * @return
     */
    @ExceptionHandler(NotLoginException.class)
    public ResponseBean NotLoginException(NotLoginException ex){
        return ResponseBean.error (ex.getMessage (),500);
    }

    /**
     * 账号被禁用
     * @param ex
     * @return
     */
    @ExceptionHandler(DisableException.class)
    public ResponseBean DisableException(DisableException ex){
        return ResponseBean.error (ex.getMessage (),501);
    }


    /**
     * 全局异常
     * @param ex
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public ResponseBean RuntimeException(RuntimeException ex){
        System.out.println (ex);
        return ResponseBean.error (ex.getMessage (),404);
    }
}
